<template>
  <div class="linkage">
    <div>
      <el-select v-model="selectProvince" filterable size="small" @change="selectProvinceFun($event)" placeholder="请选择省份">
        <!-- <el-option value="" label="请选择省份"></el-option> -->
        <!-- 组件传值（子传父） ： @click.native="sendPronvince()"-->
        <el-option :value="item" :label="item.label" v-for="(item, index) in city" :key="index" @click.native="sendPronvince()"></el-option>
      </el-select>
    </div>
    <div>
      <el-select v-model="selectCity" filterable size="small" @change="selectCityFun($event)" placeholder="请选择城市">
        <!-- <el-option value="" label="请选择城市"></el-option> -->
        <el-option :value="item" :label="item.label" v-for="(item, index) in cityList" :key="index" @click.native="sendCity()"></el-option>
      </el-select>
    </div>
    <div>
      <el-select v-model="selectArea" filterable size="small" @change="selectAreaFun($event)" placeholder="请选择区县">
        <!-- <el-option value="" label="请选择区县"></el-option> -->
        <el-option :value="item" :label="item.label" v-for="(item, index) in areaList" :key="index" @click.native="sendRegion()"></el-option>
      </el-select>
    </div>
  </div>
</template>
<script>
import city from '../assets/city_code.json'
export default {
  name: 'linkage',
  data () {
    return {
      // 整个省市县数据
      city: city,
      // 被选中的市数据
      cityList: [],
      // 被选中的县数据
      areaList: [],

      selectProvince: {},
      selectCity: {},
      selectArea: {}
    }
  },
  created:function(){
    // console.log('created!');
  },
  mounted () {
  },
  methods: {
    // 省份 市 县联动
    selectProvinceFun (event) {
      console.log(event.label)
      if (event) {
        this.cityList = event.children
      } else {
        this.cityList = []
      }
      this.areaList = []
      this.$emit('getLawyerListInfo', [event.label, 'province'])
      this.selectProvince = event.label
    },
    selectCityFun (event) {
      console.log(event.label)
      if (event) {
        this.areaList = event.children
      } else {
        this.areaList = []
      }
      this.$emit('getLawyerListInfo', [event.label, 'city'])
      this.selectCity = event.label
    },
    selectAreaFun (event) {
      console.log(event.label)
      this.$emit('getLawyerListInfo', [event.label, 'area'])
      this.selectArea = event.label
      console.log(this.selectProvince,this.selectCity,this.selectArea);
    },
    //组件传值（子传父）
    sendPronvince(){
      // console.log("传值啦");
      // console.log("省份传值：",this.selectProvince);
      this.$emit("listenProvince",this.selectProvince)
    },
    sendCity(){
      // console.log("传值啦");
      // console.log("城市传值：",this.selectCity);
      this.$emit("listenCity",this.selectCity)
    },
    sendRegion(){
      // console.log("传值啦");
      // console.log("县区传值：",this.selectArea);
      this.$emit("listenRegion",this.selectArea)
    }

  }
}
</script>
<style lang="less" scoped>
  .linkage {
    display: flex;
    margin-right: 10px;
  }
  .el-select{
    margin-right: 2px;
  }
</style>
